<template>
  <div class="w-1920px">
    <div class="m-auto w-1445px mb-40px btn-wrap">
      <div class="btn-l" @click="prev">
        <el-icon class="mt-14px"><ArrowLeftBold /></el-icon>
      </div>
      <div class="btn-r" @click="next">
        <el-icon class="mt-14px"><ArrowRightBold /></el-icon>
      </div>
      <el-carousel
        ref="carousel_ref"
        class="mt-55px"
        :interval="4000"
        type="card"
        height="400px"
        :autoplay="false"
        indicator-position="none"
        arrow="never"
      >
        <el-carousel-item v-for="item in list" :key="item.id">
          <div class="shadow flex flex-item-center" @click="go_play(item.id)">
            <div class="mt-50px mx-30px text-center">
              <p class="text-49px mt-10px mb-15px">{{ item.teacher }}</p>
              <p class="text-40px mt-10px">{{ item.title }}</p>
            </div>
            <img
              ref="bannerImg"
              class="img w-303px h-393px"
              :src="item.teacher_header_img"
            />
          </div>
        </el-carousel-item>
      </el-carousel>
      <el-dialog
        v-model="operation_dialog"
        :show-close="true"
        title=""
        width="1200px"
        top="20vh"
      >
        <div class="ml-550px w-560px bg-#fcf9f9 py-60px px-50px">
          <el-menu
            :default-active="default_active"
            mode="horizontal"
            :ellipsis="false"
            @select="handleSelect"
            background-color="transparent"
            text-color="#000"
            active-text-color="#000"
            class="mt--20px mb-20px"
          >
            <el-menu-item index="login">
              <template #title>
                <span>密码登录</span>
              </template>
            </el-menu-item>
            <el-menu-item index="code_login">
              <template #title>
                <span>验证码登录</span>
              </template>
            </el-menu-item>
          </el-menu>
          <component :is="is" @close_login="close_login" />
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { window_list } from "@/api/index";
import { useRouter } from "vue-router";
import Login from "./login.vue";
import codeLogin from "./codeLogin.vue";
import useUserStore from "@/store/modules/user";

const carousel_ref = ref(null);
let userStore = useUserStore();
const default_active = ref("login");
const operation_dialog = ref(false);
const is = ref(null);
const mapping = ref({
  login: Login,
  code_login: codeLogin,
});

const video_id = ref();
const list = ref([]);
const $router = useRouter();

const prev = () => {
  carousel_ref.value.prev();
};
const next = () => {
  carousel_ref.value.next();
};
const get_window_list = async () => {
  const {
    data: { data },
  } = await window_list();
  list.value = data;
};
get_window_list();

const handleSelect = (key, path) => {
  default_active.value = key;
  is.value = mapping.value[key];
};

const close_login = (show) => {
  operation_dialog.value = show;
  $router.push(`/search/play3?id=${video_id.value}`);
};

const go_play = (id) => {
  console.log(typeof id);
  video_id.value = id;
  if (!userStore.user_info.name) {
    operation_dialog.value = true;
    is.value = mapping.value["login"];
  } else {
    $router.push(`/search/play3?id=${id}`);
  }
};
</script>

<style scoped>
.btn-wrap {
  position: relative;
}
.btn-l {
  position: absolute;
  top: 156px;
  left: -141px;
  width: 79px;
  height: 79px;
  background-color: #afafaf;
  border-radius: 50% !important;
  font-size: 39px;
  color: #fff;
  text-align: center;
  line-height: 70px;
  cursor: pointer;
}
.btn-r {
  position: absolute;
  top: 156px;
  right: -164px;
  width: 79px;
  height: 79px;
  background-color: #b33f49;
  border-radius: 50% !important;
  text-align: center;
  cursor: pointer;
}
::v-deep .el-menu--horizontal .el-menu-item:not(.is-disabled):focus,
.el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
  background-color: #fff !important;
}
::v-deep .el-menu--horizontal > .el-menu-item.is-active {
  border-bottom: 3px solid #bb0615;
  background-color: #fff !important;
}
::v-deep .el-menu-item:hover {
  font-size: 20px;
  border-bottom: 3px solid #bb0615;
  background-color: #fff !important;
}
::v-deep .el-menu-item {
  font-size: 20px;
  line-height: 36px;
}
::v-deep .el-menu--horizontal {
  border-bottom: none;
}
::v-deep .el-dialog {
  height: 550px;
  background-image: url("/login_bg.png");
  background-size: cover;
}
.shadow {
  width: auto;
  height: 393px;
  background-color: #fbfbfb;
  border-radius: 20px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}
:deep .el-dialog__headerbtn .el-dialog__close {
  color: #333 !important;
}
:deep .el-icon {
  /* width: 500px !important;
  height: 37px !important; */
  color: #fff !important;
  font-size: 50px;
  font-weight: 600;
}
:deep .el-carousel__arrow {
  width: 48px;
  height: 41px;
  border-radius: 0 !important;
  background-color: #000000;
  opacity: 0.48;
}
:deep .el-carousel__arrow--left {
  /* margin-top: -10px;
  left: 0; */
  width: 79px;
  height: 79px;
  background-color: #afafaf;
  border-radius: 50% !important;
}
:deep .el-carousel__arrow--right {
  width: 79px;
  height: 79px;
  background-color: #b33f49;
  border-radius: 50% !important;
}
.img {
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
}
</style>
